<?php

namespace App\Http\Controllers\OpenShop\SiteLocation;

use App\Enums\OpenShop\InvestmentPromotion\SiteLocationEnum;
use App\Http\Controllers\BaseController;
use App\Http\Validate\OpenShop\SiteLocation\CustomerAnalysisValidate;
use App\Http\Validate\OpenShop\SiteLocation\ProductAnalysisValidate;
use App\Http\Validate\OpenShop\SiteLocation\SubmitFileValidate;
use App\Http\Validate\OpenShop\SiteLocation\SubmitFormValidate;
use App\Models\Common\FsCompanyUserModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopLocationModel;
use App\Service\OpenShop\Feishu\PermissionService;
use App\Service\OpenShop\FeishuMini\ShopService;
use App\Service\OpenShop\SiteLocation\AuthService;
use App\Service\OpenShop\SiteLocation\SiteLocationAuditService;
use App\Service\OpenShop\SiteLocation\SiteLocationService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class UserController extends BaseController
{

    public function getRmsUserInfo(Request $request)
    {
        $data = AuthService::getRmsUserInfo($request);
        if ($data['position'] === SiteLocationEnum::POSITION_DEVELOP_MANAGER) {
            $scope    = PermissionService::dataPermission(PermissionService::SITE_LOCATION_PERMISSION);
            if ($scope === PermissionService::PERMISSION_ALL) {
                $data['position'] = $scope;
                $data['positionDesc'] = PermissionService::PERMISSION_TEXT_MAPPING[$scope] ?? '-';
            }
        }
        // 开店小程序首页权限
        try {
            $openMiniIndex = (new ShopService())->indexAccess();
        } catch (\Exception $e) {
            Log::warning($e);
            $openMiniIndex = false;
        }

        $data['openMiniIndex'] = $openMiniIndex;
        $data['extCompany'] = FsCompanyUserModel::checkExt($data['userId'] ?? 0, $data['feishuId'] ?? '');

        Log::info('Applet User Info...', $data);

        return $this->success($data);
    }
}
